<?php
require("includes/funciones.inc.php");
session_start();
require("includes/constants.php");

$DB = NewADOConnection('mysqlt');
$DB->Connect();
$DB->Execute("SET NAMES utf8;");
//$DB->debug=true;

//LOGIN
if(!empty($_REQUEST['txtUser']))
{
	$strSQL = "SELECT * FROM users WHERE userName = '".$_REQUEST['txtUser']."' AND userPassword = '".md5($_REQUEST["txtPass"])."'";
	
	$rsUser = $DB->Execute($strSQL); 
	if (!$rsUser->EOF)
	{
		$_SESSION['idUser'] = $rsUser->fields("idUser");
		$_SESSION['userName'] = $rsUser->fields("userName");
		$_SESSION['userCompleteName'] = $rsUser->fields("userCompleteName");
		$_SESSION['userType'] = $rsUser->fields("idTypeUser");
		
		$strSQL = "SELECT * FROM users WHERE userName = '".$_REQUEST['txtUser']."' AND userPassword = '".md5($_REQUEST["txtPass"])."'";
		$rsConfig = $DB->Execute("SELECT * FROM config ORDER BY idConfig DESC");
		
		$_SESSION['annoCampeonato'] = $rsConfig->fields("anno");
		$_SESSION['cantPalomares'] = $rsConfig->fields("cantPalomares");
		$_SESSION['cantPalomaresFondo'] = $rsConfig->fields("cantPalomaresFondo");
		
			
		Header("Location: main.php");
		exit();
	}
}

?>
<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html" />
		<link href="css/css.css" media="screen" rel="stylesheet" type="text/css" />
		<style type="text/css" title="currentStyle">
			@import "js/datatables/css/demo_table_jui.css";
			@import "js/datatables/themes/smoothness/jquery-ui-1.8.4.custom.css";
			@import "css/css.css";
			@import "css/jquery.zweatherfeed.css";
			
		</style>
		<title>-:: Asociaci&oacute;n Colomb&oacute;fila La Campanense - Lime&ntilde;a ::-</title>
		<!-- General Scripts -->
		<script type="text/javascript" src="js/jquery/jquery-1.7.1.min.js"></script>
		<script type="text/javascript" src="js/jquery/jquery-ui-1.8.16.custom.min.js"></script>
		<script type="text/javascript" src="js/jquery/jquery.zweatherfeed.js"></script>
		<!-- Form Script -->
		<script type="text/javascript" src="js/datatables/js/jquery.dataTables.min.js"></script>
		<script src="js/datatables/js/jquery.dataTables.rowGrouping.js" type="text/javascript" ></script>
		<script type="text/javascript" src="js/utils.js"></script>
		<script type="text/javascript" src="js/login.js"></script>
	</head>
	
	<body>
		<div id="contenedor">
			<div id="imgHead"></div>
			<div id="menu">
				<a href="javascript:;" onclick="showSeccion('INICIO');" id="btnInicio" name="btnInicio" class="btnMenu">Inicio</a>
				<a href="javascript:;" onclick="showSeccion('COLOMBOFILIA');" id="btnColombofilia" name="btnColombofilia" class="btnMenu">Colombofilia</a>
				<a href="javascript:;" onclick="showSeccion('COMPETENCIAS');" id="btnCompetencias" name="btnCompetencias" class="btnMenu">Competencias</a>
				<a href="javascript:;" onclick="showSeccion('CONTACTENOS');" id="btnContactenos" id="btnContactenos" class="btnMenu">Contactenos</a>
				<a href="javascript:;" onclick="showSeccion('RESULTADOS');" id="btnResultados" id="btnResultados" class="btnMenu">Resultados</a>
				<a href="javascript:;" onclick="showSeccion('CLIMA');" id="btnClima" id="btnClima" class="btnMenu">Clima</a>
				<a href="javascript:;" onclick="showSeccion('CONECTARSE');" id="btnConectarse" id="btnConectarse" class="btnMenu">Conectarse</a>
			</div>
			<div id="main">
				<div id="inicio" class="screen overflowScr">
					<?include('secciones/inicio.php');?>
				</div>
				<div id="colombofilia" class="screen overflowScr" style="display: none;">
					<?include('secciones/colombofilia.php');?>
				</div>
				<div id="competencias" class="screen overflowScr" style="display: none;">
					<?include('secciones/competencias.php');?>
				</div>
				<div id="contactenos" class="screen overflowScr" style="display: none;">
					<?include('secciones/contactenos.php');?>
				</div>
				<div id="resultados" class="screen overflowScr" style="display: none;">
					<?include('campeonatos.php');?>
				</div>
				<div id="clima" class="screen overflowScr" style="display: none;">
					<?include('clima.php');?>
				</div>
				<form id="frmLogin" name="frmLogin" method="post" action="login.php" onsubmit="return $_validateFieldsMandatoriesForm();">
					<div id="cajLog" class="screen" style="display: none; height: 350px;">			
						<div class="logTopUser">
							<p class="spanLog">Usuario</p>
							<input type="text" class="inputLog" name="txtUser" id="txtUser">
						</div>
						<div class="logTopPass">
							<p class="spanLog">Clave</p>
							<input type="password" class="inputLog" name="txtPass" id="txtPass">
							<a href="javascript:;" onclick="$('#frmLogin').submit();" class="btnIncSes">Iniciar Sesi&oacute;n</a>
						</div>
					</div>
				</form>
			</div>
			<div id="imgFooter"></div>	
		</div>
	</body>
	
	<!-- Global Message -->
	<div id="globalMess"> 
		<div class="img"></div>
		<div id="globalMessImgClose" class="imgClose"></div>
		<div id="tituloMess" class="msgTitulo">TITULO</div>
		<p id="textoMess" class="msgTexto">MENSAJE</p>
	</div>
</html> 

<script type='text/javascript'>
	$(document).ready(
	function() {
				<?php if (!empty($_POST['txtUser']) && $rsUser->EOF) { ?>
					$_showMessage('ERR', 'ERROR', 'Combinaci&oacute;n usuario/clave incorrecto');
				<?php } ?>
	});	
</script>